﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:toms="urn:TomsToolbox"
                    xmlns:styles="clr-namespace:tomenglertde.ResXManager.Styles">

  <Style x:Key="TabItemStyle" TargetType="{x:Type TabItem}">
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
    <Setter Property="Padding" Value="14,2,14,1" />
    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static styles:ResourceKeys.BorderBrush}}" />
    <Setter Property="Background" Value="{DynamicResource {x:Static  SystemColors.ControlBrushKey}}" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TabItem}">
          <Grid SnapsToDevicePixels="True">
            <Border x:Name="TabItemBorder" BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="0"
                    Background="{TemplateBinding Background}"
                    Padding="{TemplateBinding Padding}">
              <Grid HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
                    VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" >
                <ContentPresenter x:Name="Content" ContentTemplate="{TemplateBinding HeaderTemplate}"
                                  Content="{TemplateBinding Header}"
                                  ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                <Rectangle x:Name="FocusVisual" Margin="-3,-1" Visibility="Collapsed"
                           Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" 
                           StrokeThickness="1" StrokeDashArray="1 2"/>
              </Grid>
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Background" Value="{DynamicResource {x:Static styles:ResourceKeys.BorderBrush}}"/>
            </Trigger>
            <Trigger Property="IsSelected" Value="True">
              <Setter Property="Panel.ZIndex" Value="1" />
              <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}"/>
            </Trigger>
            <MultiDataTrigger>
              <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Self}}" Value="True"/>
                <Condition Binding="{Binding IsFocusVisualVisible, Source={x:Static toms:KeyboardNavigation.Current}}" Value="True" />
              </MultiDataTrigger.Conditions>
              <Setter Property="Visibility" TargetName="FocusVisual" Value="Visible"/>
            </MultiDataTrigger>
            <Trigger Property="TabStripPlacement" Value="Left">
              <Setter Property="Padding" Value="5,2,5,1" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Right">
              <Setter Property="Padding" Value="5,2,5,1" />
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="True" />
                <Condition Property="TabStripPlacement" Value="Top" />
              </MultiTrigger.Conditions>
              <Setter Property="Margin" Value="-1" />
              <Setter Property="BorderThickness" TargetName="TabItemBorder" Value="1,1,1,0" />
              <Setter Property="Margin" TargetName="Content" Value="-1,0,-1,1" />
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="True" />
                <Condition Property="TabStripPlacement" Value="Bottom" />
              </MultiTrigger.Conditions>
              <Setter Property="Margin" Value="-1" />
              <Setter Property="BorderThickness" TargetName="TabItemBorder" Value="1,0,1,1" />
              <Setter Property="Margin" TargetName="Content" Value="-1,1,-1,0" />
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="True" />
                <Condition Property="TabStripPlacement" Value="Left" />
              </MultiTrigger.Conditions>
              <Setter Property="Margin" Value="-1" />
              <Setter Property="BorderThickness" TargetName="TabItemBorder" Value="1,1,0,1" />
              <Setter Property="Margin" TargetName="Content" Value="-1,-1,0,-1" />
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="True" />
                <Condition Property="TabStripPlacement" Value="Right" />
              </MultiTrigger.Conditions>
              <Setter Property="Margin" Value="-1" />
              <Setter Property="BorderThickness" TargetName="TabItemBorder" Value="0,1,1,1" />
              <Setter Property="Margin" TargetName="Content" Value="0,-1,-1,-1" />
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="{x:Static styles:ResourceKeys.TabControlStyle}" TargetType="{x:Type TabControl}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
    <Setter Property="Padding" Value="4" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="BorderBrush" Value="{DynamicResource {x:Static styles:ResourceKeys.BorderBrush}}" />
    <Setter Property="Background" Value="{DynamicResource {x:Static  SystemColors.ControlBrushKey}}" />
    <Setter Property="HorizontalContentAlignment" Value="Center" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="ItemContainerStyle" Value="{StaticResource TabItemStyle}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TabControl}">
          <Grid ClipToBounds="True" SnapsToDevicePixels="True" KeyboardNavigation.TabNavigation="Local">
            <Grid.ColumnDefinitions>
              <ColumnDefinition x:Name="ColumnDefinition0" />
              <ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition x:Name="RowDefinition0" Height="Auto" />
              <RowDefinition x:Name="RowDefinition1" Height="*" />
            </Grid.RowDefinitions>
            <TabPanel x:Name="HeaderPanel" Grid.Column="0" IsItemsHost="True" Margin="1,1,1,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" />
            <Border x:Name="ContentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
              <ContentPresenter x:Name="PART_SelectedContentHost" ContentTemplate="{TemplateBinding SelectedContentTemplate}" Content="{TemplateBinding SelectedContent}" ContentStringFormat="{TemplateBinding SelectedContentStringFormat}" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="TabStripPlacement" Value="Bottom">
              <Setter Property="Grid.Row" TargetName="HeaderPanel" Value="1" />
              <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" />
              <Setter Property="Height" TargetName="RowDefinition0" Value="*" />
              <Setter Property="Height" TargetName="RowDefinition1" Value="Auto" />
              <Setter Property="Margin" TargetName="HeaderPanel" Value="1,0,1,1" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Left">
              <Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0" />
              <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" />
              <Setter Property="Grid.Column" TargetName="HeaderPanel" Value="0" />
              <Setter Property="Grid.Column" TargetName="ContentPanel" Value="1" />
              <Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto" />
              <Setter Property="Width" TargetName="ColumnDefinition1" Value="*" />
              <Setter Property="Height" TargetName="RowDefinition0" Value="*" />
              <Setter Property="Height" TargetName="RowDefinition1" Value="0" />
              <Setter Property="Margin" TargetName="HeaderPanel" Value="1,1,0,1" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Right">
              <Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0" />
              <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0" />
              <Setter Property="Grid.Column" TargetName="HeaderPanel" Value="1" />
              <Setter Property="Grid.Column" TargetName="ContentPanel" Value="0" />
              <Setter Property="Width" TargetName="ColumnDefinition0" Value="*" />
              <Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto" />
              <Setter Property="Height" TargetName="RowDefinition0" Value="*" />
              <Setter Property="Height" TargetName="RowDefinition1" Value="0" />
              <Setter Property="Margin" TargetName="HeaderPanel" Value="0,1,1,1" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>